<?php


namespace UU\Suite\Kernel\Traits;


use Psr\Http\Message\ServerRequestInterface;

trait InteractWithServerRequest
{
    protected ?ServerRequestInterface $request = null;

    public function getRequest(): ServerRequestInterface
    {
        if (!$this->request) {
            if (!function_exists('make')) {
                throw new \Exception('请设置请ServerRequestInterface');
            }
            return make(ServerRequestInterface::class);
        }
        return $this->request;
    }

    public function setRequest(ServerRequestInterface $request): self
    {
        $this->request = $request;

        return $this;
    }
}